import Vue from 'vue'
import App from './App.vue'
import 'babel-polyfill'
import { createRouter } from '@/widget/router/index'
import { createStore } from '@/widget/store/index'
import elementUI from './common/js/element-ui.js'
import './common/css/common.css'
import './common/css/element-ui.min.css'
import utils from './common/js/vue.prototype.js'
import { isClient } from './common/js/utils.js'

//接口缓存，IE不支持，只在服务端使用
if (!isClient()) import('./common/js/cache.js')

Vue.use(elementUI)
Vue.use(utils)

// 导出一个工厂函数，用于创建新的
// 应用程序、router 和 store 实例
export function createApp(isDoubleBind) {
  // 创建 router 实例
  const store = createStore()
  const router = createRouter(isDoubleBind)

  const app = new Vue({
    store,
    router,
    // 根实例简单的渲染应用程序组件。
    render: h => h(App)
  })

  return {
    app,
    router,
    store
  }
}
